<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class binhluan_controller extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    function __construct()
    {
        parent::__construct();
  		session_start();
		$this->load->library('util');
        $this->load->helper('url');
        $this->load->model('binhluan_model');
    } 
     
	public function index()
	{

		
		/*if($this->util->checkLogin()==false) {
			return;
		}*/
		
		$data['bar'] = $this->load->view('bar_view_admin',null,true);
		$data['sidemenu'] = $this->load->view('sidemenu_admin_view',null,true);
		
		$this->util->connect();
		$this->load->model('binhluan_model');
		//$data['chuyenmucs'] = $this->Comment_model->getChuyenmuc($mataikhoan);
		
		$data['binhluan'] = $this->binhluan_model->getBinhluan();
		$this->load->view('binhluan_view',$data);
		
	}
	
	public function xoabinhluan(){
		
		$data['bar'] = $this->load->view('bar_view_admin',null,true);
		$data['sidemenu'] = $this->load->view('sidemenu_admin_view',null,true);
		
		$this->util->connect();
		$this->load->model('binhluan_model');
		
		$mabl = $_POST['mabl'];
		
		$this->binhluan_model->xoaBinhluan($mabl);
		$data['binhluan'] = $this->binhluan_model->getBinhluan();
		
		$this->load->view('binhluan_view_ajax.php', $data);
	}
    
    public function xembinhluan()
    {
        $masp = $this->input->post('masp');
        $data['binhluans'] = $this->binhluan_model->laybinhluantheomasp($masp);
                
        echo $this->load->view('xembinhluan_view', $data);
    }
    
    public function guibinhluan()
    {
        $this->load->model('taikhoan_model');
        $mataikhoan = $_SESSION['mataikhoan'];
        $manguoidanhgia = $this->taikhoan_model->laynguoidanhgia($mataikhoan);
        $masanpham = $this->input->post('masp');
        $noidung = $this->input->post('noidung');
        if($manguoidanhgia == '' || $manguoidanhgia == null)
        {
            echo -1;
        }
        else
        {
            $this->binhluan_model->thembinhluan($masanpham, $manguoidanhgia, $noidung);
        }
    }
}